/*2.验证匿名管道的性质：
- 是否发生读阻塞？ yes
- 是否发生写阻塞？ no
- 读端先关闭，写端继续写会怎么样？Program received signal SIGPIPE, Broken pipe.管道破裂中断
- 写端先关闭，读端继续读会怎么样？read返回0
*/

#include <header.h>
int main(int argc, char* argv[]){
	
	// 0读，1写
	int pipefd[2];
	int ret = pipe(pipefd);
	ERROR_CHECK(ret, -1, "pipe");

	pid_t pid =  fork();
	ERROR_CHECK(pid, -1, "fork");

	if(pid == 0){
		// child
		sleep(3);
		close(pipefd[1]);

	
		char buf[5];
		size_t bytes = read(pipefd[0], buf, 5);
		printf("%lu\n", bytes);
		printf("child get message: %s \n", buf);
		printf("end\n");
		
	}else{
		// father
		
		close(pipefd[0]);
		close(pipefd[1]);

		wait(NULL);
				
	}
	return 0;
}